﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- InstanceBegin template="/Templates/ezdesk_app_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- InstanceBeginEditable name="pageTitle" -->
    <title>易得桌面</title>
    <!-- InstanceEndEditable -->
    <link href="Content/jquery-ui.custom.css" rel="stylesheet" type="text/css" />
    <link href="Content/ui.textbox.css" type="text/css" rel="stylesheet" media="all" />
    <link href="Content/freecontent.css" rel="stylesheet" type="text/css" />
    <link href="Content/wdatepicker.css" rel="stylesheet" type="text/css" />
    <link href="Content/ajaxbusy.css" rel="stylesheet" type="text/css" />
    <link href="Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/ezdesk_mockdata.js" type="text/javascript"></script>
    <script src="Scripts/jquery.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.custom.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="Scripts/ui.textbox.js" type="text/javascript"></script>
    <script src="Scripts/pinyin.js" type="text/javascript"></script>
    <script src="Scripts/ezdesk-jquery-ui.js" type="text/javascript"></script>
    <script src="Scripts/ezdesk_common.js" type="text/javascript"></script>
</head>
<!-- InstanceBeginEditable name="pageStyles" -->
<link href="Content/table_jui.css" rel="stylesheet" type="text/css" />
<style type="text/css"></style>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="pageScripts" -->
<script src="Scripts/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
    //************* URL常量
    var URL_ = "";
    //************* 全局变量
    var g_Var = {
        "time": null,
        "isNeedToWork": true,
        "currentDate": null
    };
    //************* 常量定义
    var StaticResource = {
        "WeekendInfo": {
            "false": "非周末",
            "true": "周末"
        },
        "IsNeedToWork": {
            "false": "休息",
            "true": "正常上班"
        },
        "AttendanceType": {
            "onDuty": "上班: ",
            "offDuty": "下班: "
        },
        "AttendanceEvaluation": {
            "Late": "迟到: ",
            "LeaveEarly": "早退: ",
            "Absense": "[旷工]",
            "ExtraWork": "[加班]",
            "ManHours": "获得工时: "
        },

        "timeTarget": {
            "minute": "分钟",
            "hour": "小时"
        },


        "leaveInfo": {
            "leaveForWorkOrNot": {
                "true": "[工作假期]",
                "false": "[个人假期]"
            },

            "leaveTime": "时间: ",
            "leaveType": "类别: "
        }
    };



    var convertor = {
        "员工": function (item) {
            var targetUserName = item.TargetUser.Name;
            var targetUserDeptName = item.TargetUser.Dept.DeptName;
            return targetUserName + "<br/>" + "(" + targetUserDeptName + ")";
        },
        "考勤记录": function (item) {
            //打卡所有记录
            var attendanceDetail = "";
            var brTarget = "<br\>"
            var attendanceList = item.AttendanceInfoList;
            var isAbnormalAttendance = false;
            for (var key in attendanceList) {
                var actionTime = Date.fromEpoch(attendanceList[key].ActionTime);
                var actionTimeFormat = actionTime.toFullTimeFormat();

                //是否正常考勤
                if (attendanceList[key].IsAbnormalAttendance) {
                    isAbnormalAttendance = true;
                }

                //上班
                if (attendanceList[key].AttendanceType == "onDuty") {
                    attendanceType = getAttendanceType(isAbnormalAttendance, "onDuty")
                    attendanceDetail = attendanceDetail
                                   + attendanceType
                                   + actionTimeFormat
                                   + brTarget;
                }
                // 下班：
                else {
                    attendanceType = getAttendanceType(isAbnormalAttendance, "offDuty")
                    attendanceDetail = attendanceDetail
                                   + attendanceType
                                   + actionTimeFormat
                                   + brTarget;
                }
            }

            return attendanceDetail;

        },

        "考勤评估": function (item) {
            var attendanceEvaluation = item.AttendanceEvaluation;
            var evaluationInfo = getAttendanceEvaluationString(attendanceEvaluation)

            return evaluationInfo;
        },

        "假期": function (item) {
            var leaveInfo = "";
            var brTarget = "<br\>"

            if (item.LeaveInfo) {
                var leaveList = item.LeaveInfo.Leaves;
                for (var key in leaveList) {
                    var isForWork = leaveList[key].IsForWork;
                    var startTime = Date.fromEpoch(leaveList[key].StartTime);
                    var endTime = Date.fromEpoch(leaveList[key].EndTime);
                    var startTimeFormat = startTime.toFullTimeFormat();
                    var endTimeFormat = endTime.toFullTimeFormat();

                    var leaveTime = startTimeFormat + " 至 " + endTimeFormat;

                    //todo:
                    //太多了
                    leaveInfo = leaveInfo
                       + StaticResource.leaveInfo.leaveType
                       + leaveList[key].LeaveName
                       + StaticResource.leaveInfo.leaveForWorkOrNot[isForWork]
                       + brTarget
                       + StaticResource.leaveInfo.leaveTime
                       + leaveTime
                       + brTarget
                       + brTarget;
                }
            }

            return leaveInfo;

        },


        "工时": function (item) {
            //实际工时
            var mouHoursInfo = (item.AttendanceEvaluation.Manhours) / 10.00;

            return mouHoursInfo + StaticResource.timeTarget.hour;

        },

        "操作": function (item) {
            //点击详细后的跳转处理
            //参数 time, userId
            var editDom = '<a onclick="trunToDetail(\'{userId}\')">详细</a>';
            editDom = editDom.replace("{userId}", item.TargetUser.Id);

            return editDom;
        }



    };
    //************* Accessor访问器
    var EzAccessor = {};
    function CreateAccessor() {
        if (ezmock.IS_MOCKED) {
            EzAccessor = CreateMockEzAccessor();

        } else {
            EzAccessor = CreateRealEzAccessor();
        }
    }


    function CreateMockEzAccessor() {
        var mock_dayAttendanceDetail = [{ "TargetUser": { "Id": "19f1c421-280f-4935-9980-e469175461c2", "Name": "龚伟", "UserName": "gw", "Dept": { "Id": "5d83f6f5-a149-4112-a07a-14ad2d51cacb", "DeptName": "施工图部", "GroupId": "7c5fc3e7-cd9a-4dc6-a901-79cc42e7f310"} }, "AttendanceInfoList": [{ "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "onDuty", "ActionTime": "1289372900", "Explanation": "去银行", "IsAbnormalAttendance": false }, { "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "onDuty", "ActionTime": "1289359900", "Explanation": "", "IsAbnormalAttendance": false }, { "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "offDuty", "ActionTime": "1289380900", "Explanation": "", "IsAbnormalAttendance": true}], "AttendanceEvaluation": { "UserId": "00000000-0000-0000-0000-000000000000", "Id": "00000000-0000-0000-0000-000000000000", "Date": "\/Date(-62135596800000)\/", "IsNeedToWork": true, "IsLate": true, "LateMiniutes": 30, "IsLeaveEarly": true, "EarlyMiniutes": 20, "IsAbsense": false, "IsExtraWork": true, "Manhours": 80 }, "LeaveInfo": { "IsWholeDay": true, "Date": "1289359500", "Leaves": [{ "LeaveName": "事假", "LeaveId": "00000000-0000-0000-0000-000000000000", "Day": "\/Date(-62135596800000)\/", "StartTime": "1289354400", "EndTime": "1289359900", "IsForWork": true }, { "LeaveName": "病假", "LeaveId": "00000000-0000-0000-0000-000000000000", "Day": "\/Date(-62135596800000)\/", "StartTime": "1289341900", "EndTime": "1289369900", "IsForWork": false}]} },

    { "TargetUser": { "Id": "19f1c421-280f-4935-9980-e469175461c3", "Name": "卢春叶", "UserName": "gw", "Dept": { "Id": "5d83f6f5-a149-4112-a07a-14ad2d51cacb", "DeptName": "行政部", "GroupId": "7c5fc3e7-cd9a-4dc6-a901-79cc42e7f310"} }, "AttendanceInfoList": [{ "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "onDuty", "ActionTime": "1289372900", "Explanation": "去银行", "IsAbnormalAttendance": false }, { "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "onDuty", "ActionTime": "1289354900", "Explanation": "", "IsAbnormalAttendance": false }, { "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "onDuty", "ActionTime": "1289370900", "Explanation": "", "IsAbnormalAttendance": true}], "AttendanceEvaluation": { "UserId": "00000000-0000-0000-0000-000000000000", "Id": "00000000-0000-0000-0000-000000000000", "Date": "\/Date(-62135596800000)\/", "IsNeedToWork": true, "IsLate": "", "LateMiniutes": "", "IsLeaveEarly": "", "EarlyMiniutes": "", "IsAbsense": true, "IsExtraWork": true, "Manhours": 45 }, "LeaveInfo": { "IsWholeDay": true, "Date": "1289359500", "Leaves": [{ "LeaveName": "婚假", "LeaveId": "00000000-0000-0000-0000-000000000000", "Day": "\/Date(-62135596800000)\/", "StartTime": "1289314400", "EndTime": "1289349900", "IsForWork": false}]} },

    { "TargetUser": { "Id": "19f1c421-280f-4935-9980-e469175461c4", "Name": "杨鑫诚", "UserName": "gw", "Dept": { "Id": "5d83f6f5-a149-4112-a07a-14ad2d51cacb", "DeptName": "行政部", "GroupId": "7c5fc3e7-cd9a-4dc6-a901-79cc42e7f310"} }, "AttendanceInfoList": [{ "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "onDuty", "ActionTime": "1289372900", "Explanation": "去银行", "IsAbnormalAttendance": false }, { "Id": "00000000-0000-0000-0000-000000000000", "UserId": "00000000-0000-0000-0000-000000000000", "Date": "1289359900", "AttendanceType": "offDuty", "ActionTime": "1289370900", "Explanation": "", "IsAbnormalAttendance": false}], "AttendanceEvaluation": { "UserId": "00000000-0000-0000-0000-000000000000", "Id": "00000000-0000-0000-0000-000000000000", "Date": "\/Date(-62135596800000)\/", "IsNeedToWork": true, "IsLate": "", "LateMiniutes": "", "IsLeaveEarly": "", "EarlyMiniutes": "", "IsAbsense": false, "IsExtraWork": false, "Manhours": 80 }, "LeaveInfo": { "IsWholeDay": true, "Date": "1289359500", "Leaves": []} }
    ];

        var mock_dayInfo = {
            "Date": "1243180800",
            "IsNeedToWork": true,
            "HolidayInfo": {
                "Name": "国庆节"
            },
            "ExtraShiftInfo": {
                "Name": "年假"
            },
            "IsWeekEnd": false
        };

        var mock_currentDate = "1243180800";
        //模拟实现服务器交互方法
        var mockEzAccessor = {
            "getDayInfo": function () {
                return mock_dayInfo;
            },

            "getDayAttendanceDetailList": function () {
                return mock_dayAttendanceDetail;
            },
            "getCurrentDate": function () {

                return mock_currentDate;
            }
        };

        return mockEzAccessor;
    }



    function CreateRealEzAccessor() {
        //实现服务器交互方法
        var realEzAccessor = {
            "getDayInfo": function () {
                //                return <%=ViewData["DayInfo"]%>;
            },
            "getCurrentDate": function () {

                //                return <%=ViewData["CurrentDate"]%>;
            },

            "getDayAttendanceDetailList": function () {
                //                return <%=ViewData["DayAttendanceDetailList"]%>;
            }

        };

        return realEzAccessor;
    }

    function getAttendanceType(bool, AttendanceType) {
        var attendanceType = StaticResource.AttendanceType[AttendanceType];
        //是否正常考勤
        if (bool) {
            attendanceType = "*" + attendanceType;
        }

        return attendanceType;

    }



    function getAttendanceEvaluationString(attendanceEvaluation) {
        var late = StaticResource.AttendanceEvaluation.Late;
        var leaveEarly = StaticResource.AttendanceEvaluation.LeaveEarly;
        var absence = StaticResource.AttendanceEvaluation.Absense;
        var extraWork = StaticResource.AttendanceEvaluation.ExtraWork;
        var minuteTarget = StaticResource.timeTarget.minute;

        var brTarget = "<br\>";
        var evaluationInfo = "";
        if (g_Var.isNeedToWork) {
            //迟到
            if (attendanceEvaluation.LateMiniutes > 0) {
                evaluationInfo = evaluationInfo
                        + late
                        + attendanceEvaluation.LateMiniutes
                        + minuteTarget
                        + brTarget;
            }
            //早退
            if (attendanceEvaluation.EarlyMiniutes > 0) {
                evaluationInfo = evaluationInfo
                        + leaveEarly
                        + attendanceEvaluation.EarlyMiniutes
                        + minuteTarget
                        + brTarget;
            }
        }
        //旷工
        if (attendanceEvaluation.IsAbsense) {
            evaluationInfo = evaluationInfo
                        + absence
                        + brTarget;

        }
        //加班
        if (attendanceEvaluation.IsExtraWork) {
            evaluationInfo = evaluationInfo
                        + extraWork
                        + brTarget;

        }

        return evaluationInfo;

    }



    function setTableColumn() {
        var userColumnHead = $('#tblAttendanceList thead tr th')[0];
        $(userColumnHead).css({
            'width': '60px'
        });

        var actionTimeColumnHead = $('#tblAttendanceList thead tr th')[1];
        $(actionTimeColumnHead).css({
            'width': '90px'
        });

        var evaluationColumnHead = $('#tblAttendanceList thead tr th')[2];
        $(evaluationColumnHead).css({
            'width': '90px'
        });

        var manHoursColumnHead = $('#tblAttendanceList thead tr')[4];
        $(manHoursColumnHead).css({
            'width': '90px'
        });


        var detailColumnHead = $('#tblAttendanceList thead tr th')[5];
        $(detailColumnHead).css({
            'width': '30px'
        });


    }


    function bindAttendanceList(originalJson) {
        var data = DataConverterForDataTable.convertData(originalJson, convertor);

        data.bPaginate = false;
        data.bRetrieve = true;
        data.bFilter = false;
        data.bSort = false;
        data.bInfo = false;

        $('#cmbAttendanceListPerDay')
          .empty();
        var tblAttendanceList = $('<table id="tblAttendanceList" class="tbl"/>')
          .appendTo('#cmbAttendanceListPerDay');
        $('#tblAttendanceList')
          .dataTable(data)

        //设置表格列宽
        setTableColumn();

    }


    function trunToDetail(userId) {
        window.location.href = "ModifyAttendanceInfoPerDay?UserId="
                           + userId
                           + "&time="
                           + g_Var["time"];
    }


    function showDayInfo(dayInfo) {
        var isWeekEnd = StaticResource.WeekendInfo[dayInfo.IsWeekEnd];
        var needToWork = StaticResource.IsNeedToWork[dayInfo.IsNeedToWork];
        var extraShiftInfo = "";
        var holidayInfo = "";

        if (dayInfo.ExtraShiftInfo && dayInfo.HolidayInfo) {
            extraShiftInfo = dayInfo.ExtraShiftInfo.Name;
            holidayInfo = dayInfo.HolidayInfo.Name;
        }

        var dayInfoDom = '<p>当日信息 : {weekendInfo}  {holidayInfo}  {extraShiftInfo} {needToWork}</p>';
        dayInfoDom = dayInfoDom.replace("{weekendInfo}", isWeekEnd)
                           .replace("{holidayInfo}", holidayInfo)
                           .replace("{extraShiftInfo}", extraShiftInfo)
                           .replace("{needToWork}", needToWork);

        $('#lblDayInfo').append(dayInfoDom);
    }



    function showAttendanceDetailTittle(dayInfo) {
        var nowDay = Date.fromEpoch(dayInfo.Date).toFullChineseDateFormat();
        var tittleStr = nowDay + " " + "全体员工考勤详细";

        $('#lblTittle').html(tittleStr);
    }



    function initPage() {
        EzTipsManager.addTipBox('#tip_Remind', 'tipRemind');
        EzTipsManager.showTipBox('tipRemind');

        CreateAccessor();
        var dayInfo = EzAccessor.getDayInfo();
        var attendanceList = EzAccessor.getDayAttendanceDetailList();

        g_Var["time"] = dayInfo.Date;
        g_Var["isNeedToWork"] = dayInfo.IsNeedToWork
        g_Var["currentDate"] = EzAccessor.getCurrentDate();

        showDayInfo(dayInfo);
        showAttendanceDetailTittle(dayInfo);

        if (g_Var.time <= g_Var.currentDate) {
            //绑定考勤信息
            bindAttendanceList(attendanceList);
        }
        else {
            $('#tblNoFuture').show();
            $('#cmbAttendanceListPerDay').hide();
        }


    }
    function initPageEvent() {

        $('#preDay').click(function () {
            var currentDate = Date.fromEpoch(g_Var["time"]);

            var perDay = new Date(
                currentDate.getFullYear(),
                currentDate.getMonth(),
                currentDate.getDate() - 1,
                0,
                0,
                0
            ).toEpoch();

            window.location.href = "AttendanceInfoListPerDayManager?time="
                           + perDay;

        });


        $('#nextDay').click(function () {
            var currentDate = Date.fromEpoch(g_Var["time"]);

            var nextDay = new Date(
                currentDate.getFullYear(),
                currentDate.getMonth(),
                currentDate.getDate() + 1,
                0,
                0,
                0
            ).toEpoch();

            window.location.href = "AttendanceInfoListPerDayManager?time="
                           + nextDay;
        });


    }
    $(function () {
        initPage();
        initPageEvent();
    });
</script>
<!-- InstanceEndEditable -->
<body>
    <div id="root">
        <div id="headw">
            <div id="head">
                <!-- InstanceBeginEditable name="pageHead" -->
                <p>
                    早上好，杨裕欣(软件工程部)
                </p>
                <div id="status-bar">
                    <span><a href="#">设置</a></span>&nbsp; 魏玛软件出品
                </div>
                <!-- InstanceEndEditable -->
            </div>
        </div>
        <div id="main">
            <div id="contentw">
                <div id="content-page">
                    <!-- InstanceBeginEditable name="pageContent" -->
                    <div id="page-head">
                        <span id="lblTittle"></span>
                        <div style="margin: 5px; min-height: 20px;">
                            <div style="float: left;">
                                <a id="preDay">前一天</a>
                            </div>
                            <div style="float: right;">
                                <a id="nextDay">后一天</a>
                            </div>
                        </div>
                    </div>
                    <div id="page-body">
                        <div id="lblDayInfo" style="margin: 20px; color: gray;">
                        </div>
                        <div id="tblNoFuture" style="display: none;">
                            <!--<%Html.RenderPartial("_noFutureDisplayInfo"); %>-->
                        </div>
                        <div id="cmbAttendanceListPerDay">
                        </div>
                    </div>
                    <div class="page-submit">
                    </div>
                    <!-- InstanceEndEditable -->
                </div>
                <div id="content-foot">
                    <small>这个是内容下面的脚注</small></div>
            </div>
            <div id="tipsw">
                <!-- InstanceBeginEditable name="pageShortcut" -->
                <!-- InstanceEndEditable -->
                <div id="tips" class="box">
                </div>
            </div>
            <div class="clearfloat">
            </div>
        </div>
    </div>
    <!-- InstanceBeginEditable name="pageFoot" -->
    <div id="tip_Remind" style="display: none;">
        <h1>
            小贴士:</h1>
        <p class="indent">
            这里显示的是某天全体员工的考勤相关信息，包括上下班考勤记录，假期情况以及考勤评估。
        </p>
        <p class="indent">
            点击列表后面的“详细”连接，可以查看并且修改该员工详细的当日考勤相关信息。
        </p>
    </div>
    <!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd -->
</html>
